<?php
namespace falcon5\inc;

use lucatume\DI52\Container;
use lucatume\DI52\ContainerException;

/**
 * @desc 插件初始化入口
 * Class Application
 * @package falcon5\inc
 */
class Application
{
    /**
     * @desc 全局容器
     * @var Container
     */
    private static $container;

    /**
     * @return Container
     * @desc 初始化容器
     */
    public static function container(): Container
    {
        if (is_null(self::$container)) {
            self::$container = new Container();
        }

        return self::$container;
    }

    /**
     * @return void
     * @throws ContainerException
     * @author TeamOne technical department
     * @desc 注册基础设施服务类
     */
    public static function registerInfrastructureService()
    {
        $serviceProvider = InfrastructureProviderManager::getServiceProvider();

        foreach ($serviceProvider as $service) {
            self::container()->register($service);
        }
    }

    /**
     * @return void
     * @desc 装载已注册的服务
     */
    public static function registerService()
    {
        foreach (WPProviderManager::getServiceProvider() as $class) {
            $service = WPProviderManager::instantiate($class);
            if (method_exists($service, 'register')) {
                $service->register();
            }
        }
    }


    public function make($make)
    {
        return Application::container()->make($make);
    }

}